
import { getSetUser, putSetUserUpdate } from '@/api/mine.js';
export const editMixinsMine = {
  data() {
    return {}
  },
  onLoad() {
    this.getInit()
  },
  methods: {
	async getInit(){
		const { bw_user_temp } = getApp().getBWData(['bw_user_temp']);
		if(bw_user_temp && bw_user_temp.cardId){
			for(let i in this.fromData){
				this.fromData[i] = bw_user_temp[i]
			}
		}else{
			try{
				const res = await getSetUser()
				uni.setStorageSync('bw_user_temp', JSON.stringify(res.data));
				for(let i in this.fromData){
					this.fromData[i] = res.data[i]
				}
			}catch(e){
				console.log('获取编辑用户信息失败',e)
				//TODO handle the exception
			}
		}
	},
	putInfo(){
		uni.showLoading({
			title:'保存中...',
			icon:'none'
		})
		putSetUserUpdate(this.fromData).then(res=>{
			if(res.data){ uni.navigateBack() }
		}).finally(()=>{
			uni.hideLoading()
		})
	}
  }
}